package com.zklh.leetcode.top100.problem94;

import com.zklh.leetcode.tree.model.TreeNode;

import java.util.Deque;
import java.util.LinkedList;
import java.util.List;

public class Solution2 {

    public List<Integer> inorderTraversal(TreeNode root) {
        Deque<TreeNode> deque = new LinkedList<>();
        List<Integer> trace = new LinkedList<>();
        if (root == null) {
            return trace;
        }
        TreeNode pointer = root;
        while(!deque.isEmpty() || pointer != null){
            if (pointer != null) {
                deque.push(pointer);
                pointer = pointer.left;
            } else {
                pointer = deque.poll();
                trace.add(pointer.val);
                pointer = pointer.right;
            }
        }
        return trace;
    }

}
